package cn.edu.uestc.software.config;

import cn.edu.uestc.software.intercepter.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

//@Configuration
public class LoginInterceptorConfig implements WebMvcConfigurer {
    // 将登录拦截器配置到容器中
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")                // 拦截所有的请求，不管是页面、图片、接口服务等
                .excludePathPatterns("/",              // 放行执行的路径，可能是页面、图片、接口服务等
                        "/login.html",
                        "/login/login.html",
                        "/user/login",
                        "/css/**",
                        "/images/**",
                        "/jquery/**",
                        "/js/**",
                        "/layui/**",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/v2/**",
                        "/swagger-ui.html/**");
    }

    // 配置视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
//        registry.addViewController("/").setViewName("index");
//        registry.addViewController("/index.html").setViewName("index");
    }
}
